% $Id: example.tex,v 1.1 2003/10/19 09:32:51 vverdult Exp $
%
\documentclass[pdf,blueBG,slideColor]{tudprosper}
\usepackage{listings}
\lstset{
	basicstyle=\tiny
}
%\documentclass[pdf,darkBG,slideColor]{tudprosper}  % Dark blue background 
%\documentclass[pdf,whiteBG,slideColor]{tudprosper} % White background

\title{An Instagram-like filter on an embedded platform}
\author{Bjarni Arnason \\ Quintijn	Hendrickx \\ Abhimanyu Selvan \\ Mario Voorsluys \\ \\ Group 5}

% the following five commands are optional
\institution{Master Embedded Systems}

\date{\today}
\DefaultTransition{Replace}

\begin{document}
\maketitle

%%%%%%%%%%%%%%%%%

\begin{slide}{Overview}
\begin{itemize}
\item Parallelizing the code
\item Porting the code to the embedded platform 
\item Parallelizing the code on the embedded platform
\item Optimizing performance and energy consumption
\item Conclusions
\end{itemize}
\end{slide}

%%%%%%%%%%%%%%%%%

\begin{slide}{Assignment 1}
\begin{itemize}
\item The assignment: Parallelize the filter code on a desktop computer.
\item Solution:
	\begin{itemize}
	\item[-] Multiple threads using pthread
	\item[-] Image split-up in horizontal blocks
	\item[-] Each thread filters a section of the image
	\item[-] The last thread processes extra rows if needed
	\end{itemize}
\item Problem: Differences between 32 and 64 bit
\end{itemize}
\end{slide}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Assignment 2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{slide}{Assignment 2}
\begin{itemize}
\item The assignment: Port the filter code to the CompSoC platform

\item Initial Problems:
	\begin{itemize}
	\item[-] Code size
	\item[-] Delay after last send to frame buffer
	\item[-] Size of local memory
	\end{itemize}
\end{itemize}
\end{slide}

\begin{slide}{Assignment 2}
\begin{itemize}
\item Solution:
	\begin{itemize}
	\item[-] All the work is done in Tile 2
	\item[-] Image processed in multiple iterations
	\item[-] Each iteration retains data from the previous one
	\item[-] Use of single precision instead of double
	\end{itemize}
\end{itemize}
\end{slide}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Assignment 3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{slide}{Assignment 3}
\begin{itemize}
\item The assignment: Parallelize the code on the CompSoC platform
\item Initial Problems:
	\begin{itemize}
	\item[-] Synchronization
	\item[-] Limited access to frame buffer
	\item[-] Border cases
	\end{itemize}
\end{itemize}
\end{slide}

\begin{slide}{Assignment 3}
\begin{itemize}
\item Solution:
	\begin{itemize}
	\item[-] Tile 0 and 1 filter the image
	\item[-] Tile 2 manages the data
	\item[-] Flags in synchronization registers
	\item[-] Special flags for borders
	\end{itemize}
\end{itemize}
\end{slide}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Assignment 4
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{slide}{Assignment 4}
\begin{itemize}
\item The assignment: Optimize the performance on the CompSoC platform
\item Performance Optimizations:
	\begin{itemize}
	\item[-] Filtering also on Tile 2 (when idle)	
	\item[-] Enabled compiler optimizations
	\item[-] Optimized filter function
	\end{itemize}
\item Reducing energy consumption by down-clocking
\end{itemize}
\end{slide}

\begin{slide}{Filter Optimizations}
\begin{itemize}
	\item[-] Loop merging
	\item[-] Removed unnecessary variables
	\item[-] Integer calculations instead of floating point
	\item[-] Filter kernel unrolling
	\item[-] Remove multiplications by zero
\end{itemize}
\end{slide}


\begin{slide}{Filter Optimizations}
\begin{itemize}
	\item[-] Invariant expressions outside of loop
	\item[-] Divisions replaced by reciprocal
	\item[-] Removed unnecessary operations
	\item[-] Reduced memory access
\end{itemize}
\end{slide}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Result Slides
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{slide}{Performance - Progress}
\begin{tabular}{|c|c|}
\hline 
Assignment & Worst Execution Time (million cycles)\\ 
\hline 
2 & 317.03  \\ 
\hline 
3 & 160.84 \\ 
\hline 
4 & 15.41 \\ 
\hline 
\end{tabular} 
\end{slide}

\begin{slide}{Results}
\begin{tabular}{|c|c|c|c|}
\hline 
Picture & Exec. Time (cycles) & Energy & Pixel diff \\ 
\hline 
1 & 14.56 mil. & 1.35 J & 3 \\ 
\hline 
2 & 15.38 mil. & 1.43 J & 5 \\ 
\hline 
3 & 15.41 mil. & 1.43 J & 8 \\ 
\hline 
\end{tabular} 
\end{slide}

\begin{slide}{Results}
\includegraphics[width=\textwidth]{Cycles.eps} 
\end{slide}

\begin{slide}{Results}
\includegraphics[width=\textwidth]{Energy.eps} 
\end{slide}

\begin{slide}{Results}
\includegraphics[width=\textwidth]{Product.eps} 
\end{slide}

\begin{slide}{Conclusions}
\begin{itemize}

\item Encountered challenges when working on embedded platforms
\begin{itemize}
\item[-] Memory constraints
\item[-] Platform specific data transfer API
\item[-] Find the minimum energy consumption
\item[-] Limited debugging support
\end{itemize}

\end{itemize}
\end{slide}

\maketitle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Extra slides to be used in case of questions.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{slide}{Code Fragments - Edge Filter}
\begin{lstlisting}[language=c, frame=single]
#define EdgeTreshold (61)
...
for (x = 0; x < IMAGE_WIDTH; x++) {
	Pixel pixelUp = preRow->pixels[x];
	Pixel pixelDown = postRow->pixels[x];
	int edge = (pixelCenter.R + pixelCenter.G + 
			pixelCenter.B) << 2;
	edge -= (pixelLeft.R + pixelLeft.G + pixelLeft.B);
	edge -= (pixelRight.R + pixelRight.G + pixelRight.B);
	edge -= (pixelUp.R + pixelUp.G + pixelUp.B);
	edge -= (pixelDown.R + pixelDown.G + pixelDown.B);
	...	
	if (edge <= EdgeTreshold) {
	...
	}
}
\end{lstlisting}
\end{slide}

\begin{slide}{Code Fragments - Blur Filter}
\begin{lstlisting}[language=c, frame=single]
for (x = 0; x < IMAGE_WIDTH; x++) {
  if (edge <= EdgeTreshold) {
	// Blur filter
	red = 0.2f * (pixelLeft.R + pixelRight.R + pixelUp.R 
	+ pixelDown.R + pixelCenter.R);
	green = 0.2f * (pixelLeft.G + pixelRight.G + pixelUp.G 
	+ pixelDown.G + pixelCenter.G);
	blue = 0.2f * (pixelLeft.B + pixelRight.B + pixelUp.B 
	+ pixelDown.B + pixelCenter.B);

	//Linear interpolate between source and blurred pixel
	red   = row->pixels[x].R * (1.0f - valr) + valr * red;
	green = row->pixels[x].G * (1.0f - valr) + valr * green;
	blue  = row->pixels[x].B * (1.0f - valr) + valr * blue;
  }
}
\end{lstlisting}
\end{slide}
\end{document}
